package com.fs.system.sys_admin.controller;

import com.fs.system.common.ResponseData;
import com.fs.system.sys_admin.domain.SysAdmin;
import com.fs.system.sys_admin.service.SysAdminService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysAdmin")
public class SysAdminController {

    @Resource
    private SysAdminService sysAdminService;

    /**
     * 修改
     * @param sysAdmin
     * @return
     */
    @PutMapping("/update")
    public ResponseData updateSysAdmin(@RequestBody SysAdmin sysAdmin){
        sysAdminService.updateSysAdmin(sysAdmin);
        return new ResponseData("200","更新成功");
    }

    /**
     * 查询所有
     * @param sysAdmin
     * @return
     */
    @GetMapping("/selectAllAdmin")
    public ResponseData selectAllAdmin(SysAdmin sysAdmin){
        List<SysAdmin> sysAdmins = sysAdminService.selectAll(sysAdmin);
        return new ResponseData("200","查询成功",sysAdmins);
    }

    /**
     * 分页查询
     * @param sysAdmin
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/selectPage")
    public ResponseData selectPage(SysAdmin sysAdmin,
                                   @RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize){
        PageInfo<SysAdmin> sysAdmins = sysAdminService.selectPage(sysAdmin,pageNum,pageSize);
        return new ResponseData("200","查询成功",sysAdmins);
    }

    /**
     * 添加系统管理员
     * @param sysAdmin
     * @return
     */
    @PostMapping("/addSysAdmin")
    public ResponseData addSysAdmin(@RequestBody SysAdmin sysAdmin){
        sysAdminService.addSysAdmin(sysAdmin);
        return new ResponseData("200","添加成功");
    }

    /**
     * 修改系统管理员
     * @param updateBy
     * @return
     */
    @PutMapping("/deleteSysAdmin/{sysId}")
    public ResponseData deleteSysAdmin(@PathVariable Long sysId,@RequestParam String updateBy){
        sysAdminService.deleteSysAdmin(sysId,updateBy);
        return new ResponseData("200","更新成功");
    }

    /**
     * 批量删除系统管理员
     * @param updateBy
     * @param ids
     * @return
     */
    @PutMapping("deleteBatch/{updateBy}")
    public ResponseData deleteBatch(@RequestBody List<Long> ids,@PathVariable String updateBy){
        sysAdminService.deleteBatch(ids,updateBy);
        return new ResponseData("200","更新成功");
    }
}
